package util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MyBatisUtil {
    private static SqlSessionFactory factory;
    
    static{
          InputStream is;
          try {
                is = Resources.getResourceAsStream("mybatis.xml");
                factory = new SqlSessionFactoryBuilder().build(is);
          } catch (IOException e) {
                throw new RuntimeException("MyBatis初始化失败", e);
          }
    }
    
    public static SqlSession openSession(){
          return factory.openSession();
    }
}


